﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Auditing;
using Volo.Abp.Domain.Entities;

namespace Sample.Novel.Domain.Book.Entites
{
   public class Book:Entity<Guid>, IHasCreationTime//IHasCreationTime创建时间
    {

        public string Name { get; set; }

        public string Description { get; set; }

        //书的作者 聚合和聚合之间通过聚合ID进行联系
        public Guid AuthorId { get; set; }
        public string AuthorName { get; set; }
        //类别
        public Guid CategoryId { get; set; }
        public string CategoryName { get; set; }


        public List<Volume> volumes { get; protected set;/*子集的初始化在沟站函数中创建*/ }

        public DateTime CreationTime { get;  }

        protected Book()
        {

        }
          public Book(Guid id,string name,string descrption,Guid authorId,string authorName,Guid categorId,string categoryName)
        {
            Id = id;
            Name = Check.NotNullOrWhiteSpace(name, nameof(name));
            Description = Check.NotNullOrWhiteSpace(descrption, nameof(descrption));
            AuthorId = authorId;
            AuthorName = Check.NotNullOrWhiteSpace(authorName, nameof(authorName));
            CategoryId = categorId;
            CategoryName = Check.NotNullOrWhiteSpace(categoryName, nameof(categoryName));
            volumes = new List<Volume>();

        }

        public void AddVolumes(Volume volume)
        {
            if (volumes.Any(v=>v.Title==volume.Title))
            {
                return;
            }
            volumes.Add(volume);
        }
        public void RemoveVolue(Guid volumeId)
        {
            volumes.RemoveAll(v => v.Id == volumeId);
        }
    }
}
